# coding: utf-8
import logging
import logging.handlers  # handlers要单独import


class MyLog(object):

    def __init__(self):
        pass

    @classmethod
    def set_log(self, host, port):
        logger = logging.getLogger()
        fh = logging.handlers.SysLogHandler((host, port), logging.handlers.SysLogHandler.LOG_AUTH)
        formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
        fh.setFormatter(formatter)
        logger.addHandler(fh)
        return logger

def testLog():
    log = MyLog().set_log('127.0.0.1',  514)

    msg = """
            {
                "status":"invalid",
                "ip":"10.11.11.100",
                "port": 80,
                "msg": "scan web port"
            }
        """

    for i in range(5):
        print(i)
        log.warning(msg)



testLog()
log = MyLog().set_log('127.0.0.1', 514)
log.warning("s")
